﻿using MESMian.Context;
using MESMian.Test;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MESMian.Forms.ProductionCategory
{
    public partial class ProductionCategoryDetail : DetailBase
    {

        public ProductionCategoryDetail(int primaryId) : base(primaryId)
        {
            InitializeComponent();
            Load += ProductionCategoryDetail_Load;
        }

        private void ProductionCategoryDetail_Load(object? sender, EventArgs e)
        {
            Text = "产品类型-详情";
            using (var mtx = new MyContext())
            {
                var model = mtx.ProductCategories.Find(primaryId);
                if (model != null)
                {
                    lblProductCategoryId.Text = model.ProductCategoryId.ToString();
                    lblProductCategoryName.Text = model.ProductCategoryName;
                    lblStatus.Text = model.Status == 0 ? "正常" : "禁用";
                    lblStatus.ForeColor = model.Status == 0 ? Color.Black : Color.Red;
                    var usermodel = mtx.Users.Find(model.CreateUserId);
                    if (usermodel != null)
                    {
                        lblCreateUserName.Text = usermodel.UserName;
                    }
                    lblCreateTime.Text = model.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    if (model.LastUpdateUserId != null)
                    {
                        var userModel2 =mtx.Users.Find(model.LastUpdateUserId);
                        if (userModel2 != null) { 
                            lblLastUpdateUserName.Text = userModel2.UserName;
                        }
                    }
                    else
                    {
                        lblLastUpdateUserName.Text = "无";
                    }

                    if (model.LastUpdateTime != null)
                    {
                        lblLastUpdateTime.Text = ((DateTime)model.LastUpdateTime).ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                    {
                        lblLastUpdateTime.Text = "无";
                    }
                }
            }
        }
    }
}